package com.propic.www;

import java.awt.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

import javafx.animation.FadeTransition;
import javafx.animation.PauseTransition;
import javafx.animation.SequentialTransition;
import javafx.geometry.Dimension2D;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.util.Duration;
  
class SimpleSlideShow {

    StackPane root = new StackPane();
//    ImageView[] slides;
    List<ImageView> slides = new ArrayList<ImageView>();
    int borderPic = 30;
    
    
    public SimpleSlideShow() {
        root.setMaxSize(1000, 618);
        root.setMinSize(1000, 618);



    }
    
    public void setAll(String path) {
//		File fold = new File(path);
    	List<File> filelist = FilterPhoto.getPhoto(path);
    	for(File f : filelist){
    		Image tmpimg = new Image("file:"+f.getAbsolutePath());
    		slides.add(new ImageView(tmpimg));
    	}
	}

    public StackPane getRoot() {
      return root;
    }

    // The method I am running in my class

    public void start() {
//        Dimension2D dim = Toolk

        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        SequentialTransition slideshow = new SequentialTransition();
        for (ImageView slide : slides) {
            Image image = slide.getImage();
            if (image.getHeight()/image.getWidth()>0.62) {
                slide.setFitHeight(dim.getHeight());
                slide.setFitWidth(((dim.getHeight())/image.getHeight())*image.getWidth());
            }else{
                slide.setFitHeight(((dim.getWidth())/image.getWidth())*image.getHeight());
                slide.setFitWidth(dim.getWidth());
            }

            SequentialTransition sequentialTransition = new SequentialTransition();

            FadeTransition fadeIn = getFadeTransition(slide, 0.0, 1.0, 2000);
            PauseTransition stayOn = new PauseTransition(Duration.millis(2000));
            FadeTransition fadeOut = getFadeTransition(slide, 1.0, 0.0, 2000);

            sequentialTransition.getChildren().addAll(fadeIn, stayOn, fadeOut);
            slide.setOpacity(0);

            this.root.getChildren().add(slide);
            slideshow.getChildren().add(sequentialTransition);

        }
        slideshow.play();

    }

// the method in the Transition helper class:

    public FadeTransition getFadeTransition(ImageView imageView, double fromValue, double toValue, int durationInMilliseconds) {

      FadeTransition ft = new FadeTransition(Duration.millis(durationInMilliseconds), imageView);
      ft.setFromValue(fromValue);
      ft.setToValue(toValue);

      return ft;

    }
  }